<template>
	<view>
		<view class="news_item" v-for="item in newsList" :key="item.id" @click="navTo(item.id)">
			<image :src="item.img_url"></image>
			<view class="right">
				<view class="tit">
					{{item.title}}
				</view>
				<view class="info">
					<text>发表时间：	{{item.date | formatDate}}</text>
					<text>浏览：	{{item.total}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:["newsList"],
		data() {
			return {
				
			}
		},
		filters:{
			formatDate(date){
				const nDate = new Date(date);
				const year = nDate.getFullYear();
				const month = nDate.getMonth().toString().padStart(2,0);
				const day = nDate.getDay().toString().padStart(2,0);
				const hour = nDate.getHours();
				const min = nDate.getMinutes();
				const sec = nDate.getSeconds();
				return year + "-" +month + "-" +day + " "+ hour+":"+min+":"+sec;
			}
		},
		methods: {
			navTo(id){
				this.$emit('itemClick',id);
			}
		}
	}
</script>

<style lang="scss">
.news_item{
	display: flex;
	padding: 10rpx;
	border-bottom: 1px solid $shop-color;
	image{
		width: 30%;
		height: 150rpx;
	}
	.right{
		margin-left: 15rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.tit{
			font-size: 30rpx;
		}
		.info{
			font-size: 24rpx;
			text:nth-child(2){
				margin-left:20rpx ;
			}
		}
	}
}
</style>